package net.enclosing.basecamp;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;

public class Todo {
	String id = "";
	String name = "";
	String todolistId = "";
	ToDoList toDoList = null;
	
	public static void main(String[] args) {
		
	}
	
	public String toString(){
		StringBuilder builder = new StringBuilder();
		builder.append("");
//		builder.append(id);
		builder.append(name);
		builder.append("\r\n");
//		builder.append("<br />");
		return builder.toString();
		
	}
	public static List<Todo> todosOf(ToDoList toDoList){
		String path = "todo_lists/" + toDoList.id + "/todo_items.xml";
		Document document = Basecamp.get(path);
		Element todosElement = document.getRootElement();
		List<Element> todoElements = todosElement.elements();
		List<Todo> todos = new ArrayList<Todo>();
		
		LocalStaticData staticData = new LocalStaticData();
		for (Element todoElement : todoElements) {
			System.err.println(todoElement.element("responsible-party-id")!=null);
			if(todoElement.element("responsible-party-id")!=null){
				System.err.println(todoElement.element("responsible-party-id").getText().equals(staticData.getUserid()));;
			}
			System.err.println(todoElement.elementTextTrim("completed").equals("false"));
			if(todoElement.element("responsible-party-id")!=null
				&& todoElement.element("responsible-party-id").getText().equals(String.valueOf( staticData.getUserid()))
				&& todoElement.elementTextTrim("completed").equals("false")
			){
				Todo todo = new Todo();
				todo.setId(todoElement.elementText("id"));
				todo.setName(todoElement.elementText("content"));
				todo.setTodolistId(toDoList.id);
				todo.setToDoList(toDoList);
				todos.add(todo);
				
			}
			
		}
		return todos;
	}
	

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTodolistId() {
		return todolistId;
	}

	public void setTodolistId(String todolistId) {
		this.todolistId = todolistId;
	}

	public ToDoList getToDoList() {
		return toDoList;
	}

	public void setToDoList(ToDoList toDoList) {
		this.toDoList = toDoList;
	}
	
}
